﻿<Window x:Class="SellAvi.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:views="clr-namespace:SellAvi.Views"
        xmlns:converters="clr-namespace:SellAvi.Views.Converters"
        xmlns:properties="clr-namespace:SellAvi.Properties"
        mc:Ignorable="d"
        Title="SellAvi - автоматическое управление объявлениями на Avito" Height="620" Width="900"
        DataContext="{Binding Main, Source={StaticResource Locator}}" Icon="/SellAvi;component/Resources/Sexy girl.png"
        >
    <Window.Resources>
        <ResourceDictionary>
            
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Views/Styles/MainExpanderResources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            
            <converters:InverseBooleanConverter x:Key="ibc" />
            <converters:BooleanToVisibilityConverter x:Key="bvc" />
        
        <!--http://stackoverflow.com/questions/80388/wpf-data-triggers-and-story-boards-->
            <Style x:Key="ImageBlinking"  TargetType="{x:Type Image}">
                <Setter Property="Opacity" Value="1" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding CurrentIp}" Value="подключение...">
                        <Setter Property="Opacity" Value="1"/>
                        <DataTrigger.EnterActions>
                            <BeginStoryboard x:Name="beginAnimation">
                                <Storyboard>
                                    <DoubleAnimation  BeginTime="0:0:4" Duration="0:0:0.5" Storyboard.TargetProperty="(Image.Opacity)" From="1.0" To="0.0" RepeatBehavior="Forever" AutoReverse="True" />
                                </Storyboard>
                            </BeginStoryboard>
                        </DataTrigger.EnterActions>
                        <DataTrigger.ExitActions>
                            <StopStoryboard
                            BeginStoryboardName="beginAnimation" />
                        </DataTrigger.ExitActions>
                    </DataTrigger>
                </Style.Triggers>
            </Style>
        </ResourceDictionary>
    </Window.Resources>

    <!--<Window.CommandBindings>
        <CommandBinding Command="NavigationCommands.BrowseBack" CanExecute="BrowseBack_CanExecute" Executed="BrowseBack_Executed" />
        <CommandBinding Command="NavigationCommands.BrowseForward" CanExecute="BrowseForward_CanExecute" Executed="BrowseForward_Executed" />
        <CommandBinding Command="NavigationCommands.GoToPage" CanExecute="GoToPage_CanExecute" Executed="GoToPage_Executed" />
    </Window.CommandBindings>-->
    <DockPanel>
        <Menu IsMainMenu="True" Height="22" VerticalAlignment="Top" DockPanel.Dock="Top" Background="#f5f5f5" BorderThickness="0,0,0,2" BorderBrush="#dddddd">
            <MenuItem Header="Программа">
                <MenuItem Header="Просмотр лицензии" Command="{Binding CallLicenseInfoCommand}"></MenuItem>
                <MenuItem Header="Отладочная информация" Command="{Binding CallDebugInfoCommand}"></MenuItem>
                <MenuItem Header="Выход" Command="ApplicationCommands.Close"></MenuItem>
            </MenuItem>
            <MenuItem Header="Пользователи">
                <MenuItem Header="Управление пользователями" Command="{Binding CallUserListCommand}"></MenuItem>
                <MenuItem Header="Перейти на страницу профиля" Command="{Binding CallProfileNavigateCommand}"></MenuItem>
            </MenuItem>
            <MenuItem Header="Товары">
                <MenuItem Header="Создать новый товар" Command="{Binding CallAddNewProductCommand}"></MenuItem>
                <MenuItem Header="Импортировать товары" Command="{Binding CallImportProductCommand}"></MenuItem>
                <MenuItem Header="Редактор товара" Command="{Binding CallAddProductCommand}"></MenuItem>
                <MenuItem Header="Загруженные фотографии" Command="{Binding CallViewPhotosCommand}"></MenuItem>
                <MenuItem Header="Каталог товаров" Command="{Binding CallViewProductsCommand}"></MenuItem>
            </MenuItem>
            <MenuItem Header="Настройки">
                <MenuItem Header="Настройки программы" Command="{Binding CallAppSettingsCommand}"></MenuItem>
                <MenuItem Header="Журнал обучения" Command="{Binding CallCustomParamsCommand}"></MenuItem>
                <MenuItem Header="Настройки мониторинга">
                    <MenuItem.Icon>
                        <Image Source="/SellAvi;component/Resources/tv.png"/>
                    </MenuItem.Icon>
                    <MenuItem IsCheckable="True" Header="Включить браузер" IsChecked="{Binding BrowserTrackChanges}"></MenuItem>
                    <MenuItem Header="Синхронизировать cookie" Command="{Binding CallBrowserGetCookiesCommand}"></MenuItem>
                    <MenuItem Header="Масштаб окна 150%" Command="{Binding CallBrowserSetZoomCommand}"></MenuItem>
                </MenuItem>
                <MenuItem x:Name="btnActivateTor" IsCheckable="True" Header="Обеспечить анонимность" Command="{Binding CallActivateTorCommand}"></MenuItem>
            </MenuItem>
        </Menu>


        <Border DockPanel.Dock="Bottom" Background="#f5f5f5" CornerRadius="4" BorderBrush="#dddddd" BorderThickness="0,2,0,0">
            <views:ControlProductUploader />
        </Border>

        <Border DockPanel.Dock="Left" Background="#f5f5f5" BorderBrush="#dddddd" BorderThickness="0,0,2,0">
            <StackPanel DockPanel.Dock="Left">
                <Expander IsExpanded="{Binding Path=IsAuthorized, Converter={StaticResource ibc}, Mode=OneWay}" Header="Авторизация"  Style="{StaticResource MainViewExpander}">
                    <views:ControlAuthenticate />
                </Expander>
                <Expander IsExpanded="True" Header="Активация объявлений"  Style="{StaticResource MainViewExpander}">
                    <views:ControlAdsActivator />
                </Expander>
                <Expander IsExpanded="True" Header="Сборщик объявлений"  Style="{StaticResource MainViewExpander}">
                    <views:ControlAdsParser />
                </Expander>
                <Expander IsExpanded="True" Header="Чат и сообщения"  Style="{StaticResource MainViewExpander}">
                    <views:ControlPriceEditor />
                </Expander>
            </StackPanel>
        </Border>



        <!--
            <Button  Command="NavigationCommands.BrowseBack" CommandTarget="{Binding ElementName=wbSample}">
                <Image Source="/Resources/arrow1_w.png" Width="16" Height="16" />
            </Button>
            <Button Command="NavigationCommands.BrowseForward" CommandTarget="{Binding ElementName=wbSample}">
                <Image Source="/Resources/arrow1_e.png" Width="16" Height="16" />
            </Button>
            <Separator />
            <TextBox Text="{Binding IEBrowser.CurrentUrl}" Width="200"></TextBox>-->

        <!--
            <TextBox Name="txtUrl" Width="300" HorizontalAlignment="Stretch" Text="{Binding ElementName=wbSample,Path=BindableSource}"/>
            <Button DockPanel.Dock="Right" Command="NavigationCommands.GoToPage" CommandTarget="{Binding ElementName=wbSample}" CommandParameter="{Binding ElementName=txtUrl,Path=Text}">
                <Image Source="/Resources/play.png" Width="16" Height="16" />
            </Button>-->

        <!--<WebBrowser Name="wbSample" Navigating="wbSample_Navigating" avitoBot:BrowserBehavior.Html="{Binding MyHtmlString}"></WebBrowser>-->
        <!--<avitoBot:WpfWebBrowserWrapper x:Name="wbSample" avitoBot:WpfWebBrowserWrapper.Html="{Binding HtmlContent}" avitoBot:WpfWebBrowserWrapper.Cookie="{Binding CK}"/>-->
        <!--<sellAvi:WpfWebBrowserWrapper x:Name="wbSample" AttachedWebClient="{Binding BrowserClientEx}"/>-->
        <DockPanel LastChildFill="True">
            <!-- Visibility="{Binding ElementName=btnActivateTor, Path=IsChecked, Converter={StaticResource bvc}}" -->
            <Border Background="#dddddd" CornerRadius="0" DockPanel.Dock="Top" Height="24" Margin="0,0,0,0" Visibility="{Binding ElementName=btnActivateTor, Path=IsChecked, Converter={StaticResource bvc}}">
                <DockPanel LastChildFill="False">
                    <Image Margin="4,1,0,0" Style="{StaticResource ImageBlinking}" Source="/SellAvi;component/Resources/lock.png" DockPanel.Dock="Left" Width="12" ></Image>
                    <TextBlock  Padding="2,3,2,0"  DockPanel.Dock="Left">
                              <Run Text="Анонимность обеспечивает IP: ["/>
                              <Run Text="{Binding CurrentIp}"/>
                              <Run Text="]"/>
                    </TextBlock>

                    <StackPanel Orientation="Horizontal" DockPanel.Dock="Right" Margin="0,0,0,0">
                        <Button Margin="0,0,4,0" Command="{Binding CallCheckIpCommand}" Background="Transparent" FontSize="10" DockPanel.Dock="Right">проверить IP</Button>
                        <Button Margin="0,0,4,0" Command="{Binding CallNewTorIdentityCommand}" Background="Transparent" FontSize="10" DockPanel.Dock="Right" IsEnabled="{Binding Source={x:Static properties:Settings.Default}, Path=TorInPriority, Mode=OneWay}">сменить IP</Button>
                        <Button Margin="0,0,4,0" Command="{Binding CallAvitoHomeNavigateCommand}" Background="Transparent" FontSize="10" DockPanel.Dock="Right">кабинет Avito</Button>
                    </StackPanel>
                </DockPanel>
            </Border>

            <TabControl x:Name="TaskTab" BorderThickness="0" Background="Transparent" DataContext="{Binding UploadProduct, Source={StaticResource Locator}}">
                <!--<i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding Path=TabChangedCommand}"
                                   CommandParameter="{Binding ElementName=TaskTab}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>-->
                <TabControl.Resources>
                    <Style TargetType="TabPanel">
                        <Setter Property="HorizontalAlignment" Value="Right"/>
                    </Style>
                    <Style TargetType="TabItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="TabItem">
                                    <Border Name="Border" BorderThickness="0" BorderBrush="Black" CornerRadius="0" Margin="2,-2,2,2">
                                        <ContentPresenter x:Name="ContentSite"
                                        VerticalAlignment="Center"
                                        HorizontalAlignment="Center"
                                        ContentSource="Header"
                                        Margin="10,2"/>
                                    </Border>
                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter TargetName="Border" Property="Background" Value="#f5f5f5" />
                                            <Setter TargetName="Border" Property="BorderThickness" Value="2,0,2,2" />
                                            <Setter TargetName="Border" Property="BorderBrush" Value="#dddddd" />
                                        </Trigger>
                                        <Trigger Property="IsSelected" Value="False">
                                            <Setter TargetName="Border" Property="Background" Value="Transparent" />
                                            <Setter TargetName="Border" Property="BorderThickness" Value="2,0,2,2" />
                                            <Setter TargetName="Border" Property="BorderBrush" Value="Transparent" />
                                        </Trigger>
                                        <Trigger Property="IsMouseOver" Value="True">
                                            <Setter TargetName="Border" Property="Background" Value="#f5f5f5" />
                                            <Setter TargetName="Border" Property="BorderThickness" Value="2,0,2,2" />
                                            <Setter TargetName="Border" Property="BorderBrush" Value="#dddddd" />
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </TabControl.Resources>


                <!--//-->
                <TabItem>
                    <TabItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/SellAvi;component/Resources/tv.png"></Image>
                            <TextBlock Padding="2,0,2,0">Мониторинг</TextBlock>
                        </StackPanel>
                    </TabItem.Header>
                    <ContentControl Name="wbSample" DataContext="{Binding Main, Source={StaticResource Locator}}" Content="{Binding IEBrowser}"></ContentControl>
                </TabItem>
                <TabItem>
                    <TabItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/SellAvi;component/Resources/addressbook.png"></Image>
                            <TextBlock  Padding="2,0,2,0" >
                              <Run Text="Список задач ["/>
                              <Run Text="{Binding TotalProductsCount, Mode=OneWay}"/>
                              <Run Text="]"/>
                            </TextBlock>
                        </StackPanel>
                    </TabItem.Header>
                    <views:ControlTaskList />
                </TabItem>
            </TabControl>
        </DockPanel>
    </DockPanel>
</Window>
